#include "sComponentRectInstance.h"
#include "sComponentRect.h"

namespace sgui
{
namespace inst
{

math::sRectsf& sComponentRectInstance::getRect()
{
	return m_rect;
}

const math::sRectsf& sComponentRectInstance::getRect() const
{
	return m_rect;
}
	
const math::sPointf& sComponentRectInstance::getOffset() const
{
	return m_offset;
}
	
void sComponentRectInstance::updateOffset()
{
	m_offset = getInstance().getOffset() + getInstance().getRect().getPosition();
}
	
const EControlState& sComponentRectInstance::getState() const
{
	return getInstance().getState();
}
	
bool sComponentRectInstance::OnEvent(const obs::sEvent& event)
{
    switch (event.getID())
	{
        case obs::EVID_MOUSE_PRESS:
		{
            if (getState() == CS_HOVER)
            {
			    CAST_EVENT(m_ev, sMousePressEvent);
                return OnPress(m_ev);
            }
		}
	}

	return false;
}
    
bool sComponentRectInstance::OnPress(const obs::sMousePressEvent& event)
{
    return getInstance().OnPress(event, this);
}

void sComponentRectInstance::OnHoverGet()
{
    //
}

void sComponentRectInstance::OnHoverRelease()
{
    //
}

void sComponentRectInstance::update()
{
	//
}

sComponentRectInstance::sComponentRectInstance(const res::sComponentRect& componentRect, sComponentInstance& instance, s32 id) :
	m_component(componentRect),
	m_instance(instance),
    m_id(id)
{
	m_rect = m_component.getRect();
	updateOffset();
}

sComponentRectInstance::~sComponentRectInstance()
{
    //
}

};
};